﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

using DateTimeExtensions;

namespace DateTimeExtensions.Tests
{
    /// <summary>
    /// Summary description for DateTimeExtentionsTests
    /// </summary>
    [TestClass]
    public class TimeExtensionsTests
    {
        private DateTime _monday;

        private DateTime _mondayMidnight;
        private DateTime _mondayNoon;

        [TestInitialize]
        public void Setup()
        {
            _monday = new DateTime(2008, 3, 3, 17, 15, 30); // monday 3rd of March, 2008, 17h 15m 30s

            _mondayMidnight = new DateTime(2008, 3, 3, 0, 0, 0);
            _mondayNoon = new DateTime(2008, 3, 3, 12, 0, 0);
        }

        [TestMethod]
        public void ResetTimeToMidnight()
        {
            Assert.AreEqual(_mondayMidnight, _monday.Midnight());
        }

        [TestMethod]
        public void ResetTimeToNoon()
        {
            Assert.AreEqual(_mondayNoon, _monday.Noon());
        }

        [TestMethod]
        public void SetTimeToMinutePrecision()
        {
            DateTime expected = _mondayMidnight.AddHours(14).AddMinutes(30);
            Assert.AreEqual(expected, _monday.SetTime(14, 30));
        }

        [TestMethod]
        public void SetTimeToSecondPrecision()
        {
            DateTime expected = _mondayMidnight.AddHours(14).AddMinutes(30).AddSeconds(15);
            Assert.AreEqual(expected, _monday.SetTime(14, 30, 15));
        }

        [TestMethod]
        public void SetTimeToMillisecondPrecision()
        {
            DateTime expected = _mondayMidnight.AddHours(14).AddMinutes(30).AddSeconds(15).AddMilliseconds(7);
            Assert.AreEqual(expected, _monday.SetTime(14, 30, 15, 7));
        }
    }
}
